const Controller = require("egg").Controller;
fruitList = [
    "王佳伟",
    "刘佳文",
    "王子扬",
    "王英杰"
]
class FruitsController extends Controller {
    async index() {
        // let query = this.ctx.request.query
        // console.log(query)
        // this.ctx.body = `传递的index值是${query.index}`
        // 在地址中写入?index=??
        this.ctx.body = fruitList;
    }
    async new() {
        this.ctx.body = `
            <form method='post' action = '/fruits'>
                <input name="fruitname">
                <button>按钮</button>
            </form>
        `
    }
    async create(){
        let fruit = this.ctx.request.body;
        fruitList.push(fruit.fruitname);
        // this.ctx.body = "添加成功"
        // 跳转到/fruits get请求
        //重定向
        this.ctx.redirect('/fruits')
    }
    // async getId(){
    //     let id = this.ctx.params.id;
    //     this.ctx.body = `传递的id是${id}`
    //     // 在地址中写入/???
    // }
    // async createPage(){
    //     this.ctx.body = `
    //         <form method='post' action = '/createfruit'>
    //             <input name="fruitname">
    //             <button>按钮</button>
    //         </form>
    //     `
    // }
    // async createFruit(){
    //     let fruit = this.ctx.request.body;
    //     fruitList.push(fruit.fruitname);
    //     this.ctx.body = "添加成功"
    // }
}
module.exports = FruitsController;